<template>
	<view class="maintainpartsearch">
		<SearchBar :keyword="prodKeyword" @input="onInput" @search="onSearch" placeholder="搜索滤芯" />
		<view class="maintainpartsearch__items">
			<block v-for="(maintainlist, index) in MaintainPartList" :key="index">
				<MaintainPartItem v-for="(maintainItem, partIndex) in maintainlist" :key="maintainItem.PartsGuid" :IsShowDeleteBtn="false"
				 :maintenanceItem="maintainItem" :Image="maintainItem.base64Img" @maintainPartItemClick="selectmaintainPartItem"></MaintainPartItem>
			</block>
			<view v-if="IsShowMsg" style="text-align: center;">{{ErrorMsg}}</view>
		</view>
		<!-- <view class="maintainpartsearch__loadmore" @click="loadPageMore" v-if="displayLoadMore">
			<text>加载更多</text>
		</view> -->
	</view>
</template>

<script>
	import SearchBar from '@/components/SearchBar';
	import MaintainPartItem from '@/components/MaintainPartItem';
	import maintainpartsearchbehavior from './maintainpartsearchbehavior'
	export default {
		mixins: [maintainpartsearchbehavior],
		components: {
			SearchBar,
			MaintainPartItem,
		},
		data() {
			return {
				MaintainPartList: [],
				prodKeyword: "",
				woId: "",
				IsShowMsg: false,
				ErrorMsg: "",
				displayLoadMore: false,
				ramAccessorieList: [],
				accessorieList: [],
			}
		},
		onLoad(e) {
			this.woId = e.woId;
		},
		onReachBottom(e) {
			if (this.ramAccessorieList.length > 0) {
				uni.showLoading({
					mask: true,
				})
				let subAccessorieList = this.ramAccessorieList.splice(0, 10);
				this.setProdPageImg(subAccessorieList).then((succ) => {
					this.MaintainPartList.push(subAccessorieList);
					uni.hideLoading()
				}, (err) => {
					uni.hideLoading()
				});
			}
		},
		methods: {
			onInput(e) {
				console.log(e);
				this.prodKeyword = e;
			},
			onSearch(e) {
				uni.showLoading({
					mask: true,
				})
				this.IsShowMsg = false;
				this.MaintainPartList = [];
				this.GetMaintainPartList().then((succ) => {
					if(succ)
					{
						this.ramAccessorieList =JSON.parse(succ);
						let subAccessorieList = this.ramAccessorieList.splice(0, 10);
						this.setProdPageImg(subAccessorieList).then((succ) => {						
							this.MaintainPartList.push(subAccessorieList);
							uni.hideLoading();
						}, (err) => {
							uni.hideLoading()
						});
					}else{
						this.IsShowMsg = true;
						this.ErrorMsg = "未搜索到相关结果。"
						uni.hideLoading()
					}
					
				}, (error) => {
					this.IsShowMsg = true;
					this.ErrorMsg = error.message;
					uni.hideLoading();
				})
			},
			//选择更换滤芯
			selectmaintainPartItem(e) {
				uni.$emit('selectmaintainPartItem', e);
				uni.navigateBack();
				//console.log("对过来");
			},
			loadPageMore(e) {

			},
		}
	}
</script>

<style lang="scss">
	@import './maintainpartsearch.scss'
</style>
